package com.ym.controller.doctor.today;

import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.common.annotations.CustomConstraint;
import com.ym.common.constant.Constants;
import com.ym.common.enums.UserUserTypeEnum;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.entity.ClinicManualEntity;
import com.ym.medical.domain.param.ClinicManualParam;
import com.ym.medical.domain.vo.ClinicManualVO;
import com.ym.medical.enums.ClinicManualContentTypeEnum;
import com.ym.medical.service.IClinicManualSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通讯录患者相关接口
 *
 * @author: 李涛
 * @version: 2019年05月22日 10:23
 */
@Api(tags = "医生端-今日必读")
@RestController
@RequestMapping(value = "/doctor/today",headers = Constants.Api.VERSION)
@Validated
public class TodayController extends BaseController {

	@Autowired
	private IClinicManualSV clinicManualSV;

	/**
	 * code 	01- 诊所违规行为及处罚原则说明  " +
	 * "02- 答题攻略大揭秘：如何才能获得“满意”评价 " +
	 * "03- 收入结算及账单查询 " +
	 * "04- 操作中遇到问题该怎么办？ " +
	 * "05- 常见问题及其处理措施 " +
	 * "06- 如何开启自己的诊所 " +
	 * "07- 加入工作室协议 " +
	 * "08- 前言，致每一位亚米医生 " +
	 * "09- 亚米医生法务条款 " +
	 * "10- 亚米问诊协议 " +
	 * "11- 工作室协议 " +
	 * "12- 法律声明及隐私权政策 " +
	 * "13- 亚米账号激活协议" +
	 * "14-用户隐私授权协议" +
	 * "15-电话问诊支付协议" +
	 * "16-图文问诊支付协议" +
	 * "17-健康币规则")
	 *
	 * @param keywords
	 * @param type
	 * @param code
	 * @param role
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "文章列表查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "keywords", value = "关键词", required = false, paramType = "query"),
			@ApiImplicitParam(name = "type", value = "文章类型", required = true, paramType = "query"),
			@ApiImplicitParam(name = "role", value = "阅读角色", required = false, paramType = "query"),
			@ApiImplicitParam(name = "code", value = "编码", required = false, paramType = "query"),
	})
	@GetMapping("/article/list")
	public APIResponse<PageInfo<ClinicManualVO>> articleList(
			String keywords,
			@CustomConstraint(ClinicManualContentTypeEnum.class) String type,
			String code,
			@CustomConstraint(UserUserTypeEnum.class) String role,
			@RequestParam(defaultValue = "1") int pageNum,
			@RequestParam(defaultValue = "5") int pageSize
	) {
		PageDomain.startPage(pageNum,pageSize,"sort","desc");
		ClinicManualParam params = new ClinicManualParam();
		params.setKeywords(keywords);
		params.setContentType(type);
		params.setState(FlagEnum.IS.getKey());
		params.setReadRole(role);
		params.setTheCodes(code);
		params.setDeleted(FlagEnum.NO.getKey());
		return successPage(clinicManualSV.listCustomer(params));
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "文章详情查看")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "articleId", value = "文章ID", required = true, paramType = "query"),
			@ApiImplicitParam(name = "width", value = "屏幕尺寸", required = true, paramType = "query"),
	})
	@GetMapping("/article/info")
	public APIResponse<ClinicManualEntity> articleInfo(
			@RequestParam Long articleId,
			@RequestParam int width
	) {
		ClinicManualEntity clinicManual = clinicManualSV.findById(articleId, width);
		return successData(clinicManual);
	}

}
